package com.value.vo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Pagination {
    /**
     * 总共多少条记录
     */
    private Long count = 0L;
    /**
     * 当前页开始位置
     */
    private int start = 0;
    /**
     * 总页数
     */
    private int totalPages = 0;
    /**
     * 当前页码
     */
    private int currentPage = 1;
    /**
     * 每页记录数
     */
    private int pageSize = 15;
    /**
     * 是否还有下一页
     */
    private boolean nextPage;
    /**
     * 是否还有前页
     */
    private boolean previousPage;
    /**
     * 其他参数
     */
    private String otherParams;
    private List<?> results;
    private Map<String, Object> params = new HashMap<String, Object>();

    public Long getCount() {
        return count;
    }

    public void setCount(int count) {
        setCount(Long.valueOf(count));
    }

    public void setCount(Long count) {
        this.count = count;
        if (this.count == 0)
            this.totalPages = 1;
        else if (this.count % pageSize == 0) {
            this.totalPages = (int) (this.count / pageSize);
        } else {
            this.totalPages = (int) (this.count / pageSize + 1);
        }
        if (currentPage == 1) {
            previousPage = false;
        } else {
            previousPage = true;
        }
        if (currentPage == totalPages) {
            nextPage = false;
        } else {
            nextPage = true;
        }
        this.start = (this.currentPage - 1) * pageSize;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Map<String, Object> getParams() {
        return params;
    }

    public void setParams(Map<String, Object> params) {
        this.params = params;
    }

    public boolean isNextPage() {
        return nextPage;
    }

    public void setNextPage(boolean nextPage) {
        this.nextPage = nextPage;
    }

    public boolean isPreviousPage() {
        return previousPage;
    }

    public void setPreviousPage(boolean previousPage) {
        this.previousPage = previousPage;
    }

    public String getOtherParams() {
        return otherParams;
    }

    public void setOtherParams(String otherParams) {
        this.otherParams = otherParams;
    }

    public List<?> getResults() {
        return results;
    }

    public void setResults(List<?> results) {
        this.results = results;
    }
}
